package com.app.Activity;

import com.app.Network.Protocol;
import com.app.outdoor.InvoikeServices.HeThongInvoike;

import android.app.Activity;
import android.app.LocalActivityManager;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TabHost;
import android.widget.TextView;
//--

public class od_MainActivity extends Activity {
	LocalActivityManager localActivity;
	Button btnTinNhan;
	TextView txtTenDangNhap;
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.od_activity_main);
		
		btnTinNhan=(Button)findViewById(R.id.btnSoTinNhan);
		txtTenDangNhap=(TextView)findViewById(R.id.txtTenDanNhap);
		getSoTinNhan();
		btnTinNhan.setText(CommonUtilities.soTinNhan+"");
		txtTenDangNhap.setText(CommonUtilities.nguoiDung.getTenDangNhap());
		TabHost tabHost = (TabHost) findViewById(android.R.id.tabhost);
		Resources res = getResources();
		localActivity = new LocalActivityManager(this, false);
		TabHost.TabSpec spSubject, spContact; 
		Intent iContact, iSubject;

		localActivity.dispatchCreate(savedInstanceState);
		tabHost.setup(localActivity);

		iContact = new Intent().setClass(this, od_ContactActivity.class);
		iSubject = new Intent().setClass(this, od_SubjectActivity.class);
		spContact = tabHost.newTabSpec("contact").setIndicator("Danh sách liên lạc", res.getDrawable(R.drawable.ic_launcher))
				.setContent(iContact);

		spSubject = tabHost.newTabSpec("subject").setIndicator("Danh sách chủ đề", res.getDrawable(R.drawable.ic_action_search))
				.setContent(iSubject);
		tabHost.addTab(spContact);
		tabHost.addTab(spSubject);
		
		btnTinNhan.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				Intent iTinNhan=new Intent(getBaseContext(),od_TinNhanActivity.class);
				startActivity(iTinNhan);
			}
		});
	}
	private void getSoTinNhan(){
		try{
			String data=HeThongInvoike.getSoTinNhanOffline(CommonUtilities.nguoiDung.getId()).trim();
			if(data!=null &&! data.equals(Protocol.SERVER_ERROR)){
				CommonUtilities.soTinNhan=Integer.parseInt(data);
			}
		}catch (Exception e) {
			CommonUtilities.soTinNhan=0;
			Log.d(Protocol.TAG,"Khong lay dc sl tinnhan"+e.getMessage());
		}
	}

}
